package com.prs.crm.service.cdxh.impl;

import java.text.DecimalFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

import com.prs.crm.dao.cdxh.MoldingTeamDao;
import com.prs.crm.domain.cdxh.Cdstock;
import com.prs.crm.domain.cdxh.CrmCustomer;
import com.prs.crm.domain.cdxh.DistributionOrder;
import com.prs.crm.domain.cdxh.DistributionOrderDetail;
import com.prs.crm.domain.cdxh.HrPerson;
import com.prs.crm.domain.cdxh.MaterialProduct;
import com.prs.crm.domain.cdxh.SaleOrderDetail;
import com.prs.crm.domain.cdxh.SerialNumberss;
import com.prs.crm.domain.cdxh.StockPrecautionary;
import com.prs.crm.domain.cdxh.cd_Product;
import com.prs.crm.domain.cdxh.molding.Molding;
import com.prs.crm.domain.cdxh.molding.MoldingPrint;
import com.prs.crm.domain.cdxh.molding.MoldingPrintDetail;
import com.prs.crm.domain.cdxh.molding.MoldingTeam;
import com.prs.crm.domain.cdxh.printing.Printing;
import com.prs.crm.domain.cdxh.production.ProvideRegime;
import com.prs.crm.domain.cdxh.wages.MoldingWages;
import com.prs.crm.service.cdxh.CdstockService;
import com.prs.crm.service.cdxh.CrmCustomerService;
import com.prs.crm.service.cdxh.DistributionOrderDetailService;
import com.prs.crm.service.cdxh.DistributionOrderService;
import com.prs.crm.service.cdxh.EarningSalService;
import com.prs.crm.service.cdxh.HrPersonService;
import com.prs.crm.service.cdxh.MaterialProductService;
import com.prs.crm.service.cdxh.MaterialTeamService;
import com.prs.crm.service.cdxh.MaterialWagesService;
import com.prs.crm.service.cdxh.MoldingPrintService;
import com.prs.crm.service.cdxh.MoldingService;
import com.prs.crm.service.cdxh.MoldingTeamService;
import com.prs.crm.service.cdxh.MoldingWagesService;
import com.prs.crm.service.cdxh.PrintWagesService;
import com.prs.crm.service.cdxh.PrintingService;
import com.prs.crm.service.cdxh.ProvideRegimeService;
import com.prs.crm.service.cdxh.SaleOrderService;
import com.prs.crm.service.cdxh.SerialNumberssService;
import com.prs.crm.service.cdxh.StockPrecautionaryService;
import com.prs.crm.service.cdxh.cd_ProductService;
import com.prs.crm.service.impl.BaseServiceImpl;

/**
 * @author LanXiaoGang
 * @E-mail:lan9liang@163.com
 * @qq:7857553326
 * @version 创建时间：2010-12-8 下午03:48:39 简单说明
 */

public class MoldingTeamServieImpl extends
		BaseServiceImpl<MoldingTeam, MoldingTeamDao> implements
		MoldingTeamService {

	private MaterialWagesService materialWagesService;

	private MaterialProductService materialProductService;

	private MoldingWagesService moldingWagesService;

	private PrintWagesService printWagesService;

	private EarningSalService earningSalService;

	private SerialNumberssService serialNumberssService;

	private MoldingPrint moldingPrint;

	private MoldingPrintService moldingPrintService;

	private cd_Product cd_Product;

	private cd_ProductService cd_ProductService;

	private Printing printing;

	private PrintingService printingService;

	private MoldingTeam moldingTeam;

	private MoldingTeamService moldingTeamService;

	private MaterialTeamService materialTeamService;

	private Molding molding;

	private MoldingService moldingService;

	private ProvideRegimeService provideRegimeService;

	private ProvideRegime provideRegime;

	private HrPerson hrPerson;

	private HrPersonService hrPersonService;

	private Cdstock cdstock;

	private CdstockService cdstockService;

	private DistributionOrder distributionOrder;

	private DistributionOrderDetailService distributionOrderDetailService;

	private DistributionOrderService distributionOrderService;

	private StockPrecautionaryService stockPrecautionaryService;

	private CrmCustomerService crmCustomerService;
	
	private SaleOrderService saleOrderService;
	/**
	 * 成型单数据
	 */
	@Override
	public void saveAllMoldingTeam(MoldingTeam moldingTeam,
			String[] moldingCodes, Integer[] orderNums,
			String[] moldingOrderPlans, String[] shaproduct_name,
			String[] shasize, String[] shacolor, String[] shaspeed,
			String[] shatemperature_A, Integer[] shaorder_num,
			Integer[] shayudingNums, Integer[] shareality_num,
			String[] shayaoqiuSxs, String[] shacustomer,
			Double[] shaxuyongliaoNums, String[] shafei_num,
			Double[] shashijiLinNums, String[] sharemark,
			String[] shatemperature_B, Integer[] shayeshengchanNums,
			String[] shahuan_num, String[] shatemperature_C, Date[] tihuoDates,
			String[] rushOrders) {

		double wages = 0.0;
		double funds = 0.0;
		int  insV=0;
		int lengths = moldingCodes.length;
		for (int i = 0; i < lengths; i++) {

			cd_Product cdOBject = this.getCd_ProductService().getProductObject(
					moldingCodes[i]);
			int printNums = cdOBject.getPrintName();
			if (printNums == 1) {
				// 要印刷
				Printing PtObject = this.getPrintingService().getPrinting(
						moldingCodes[i], moldingOrderPlans[i]);
				if (PtObject == null) {
					// 在印刷单不存在此产品
					Printing pObject = new Printing();
					pObject.setPrintCode(moldingCodes[i]);
					pObject.setPrintName(shaproduct_name[i]);
					pObject.setPrintColor(shacolor[i]);
					pObject.setPrintNorm(shasize[i]);
					pObject.setPrintTihuoDate(tihuoDates[i]);
					pObject.setPrintRushOrder(rushOrders[i]);
					pObject.setPrintOrderPlan(moldingOrderPlans[i]);
					pObject.setOrderNum(orderNums[i]);
					pObject.setBanChengNum(shareality_num[i]);
					pObject.setPrintShowState(1);
					pObject.setPrintPackWay(shaspeed[i]);
					this.getPrintingService().save(pObject);
				} else {
					// 在印刷单存在此产品
					PtObject.setBanChengNum(PtObject.getBanChengNum()
							+ shareality_num[i]);
					PtObject.setPrintShowState(2);
					this.getPrintingService().saveOrPrinting(PtObject);
				}

			} else {
				// 不印刷
				/**
				 * 对库房预警进行设置
				 */
				Cdstock stockObject = this.getCdstockService().getCdstock(
						moldingCodes[i], shaproduct_name[i]);
				if (stockObject != null) {
					int max_Nums = stockObject.getMax_amount();
					int min_Nums = stockObject.getMin_amount();
					int amount = stockObject.getAmount() + shareality_num[i];

					if (amount <= max_Nums && amount >= min_Nums) {

						stockObject.setAmount(stockObject.getAmount()
								+ shareality_num[i]);
						this.getCdstockService().saveOrStock(stockObject);
					} else {
						StockPrecautionary spobject = this
								.getStockPrecautionaryService()
								.getStockPrecautionaryByProductId(
										moldingCodes[i]);
						if (spobject != null) {
							spobject.setProductNum(spobject.getProductNum()
									+ shareality_num[i]);
							this.getStockPrecautionaryService()
									.saveOrStockPrecautionary(spobject);
						} else {
							StockPrecautionary spkk = new StockPrecautionary();
							spkk.setProductCode(moldingCodes[i]);
							spkk.setProductDownline(stockObject.getMin_amount());
							spkk.setProductUpline(stockObject.getMax_amount());
							spkk.setProductNum(amount);
							spkk.setProductName(cdOBject.getName()); //产品名称
							SaleOrderDetail dd=this.saleOrderService.getSaleOrderDetailByproductCode(moldingOrderPlans[i]);
							CrmCustomer crm=this.crmCustomerService.getCrmCustomerBycusCode(dd.getSaleOrder().getCusCode());
							spkk.setCrmcustomer(crm);        //客户名称
							spkk.setPrTitle("安全库存");
							this.getStockPrecautionaryService().save(spkk);
						}
						stockObject.setAmount(stockObject.getAmount()
								+ shareality_num[i]);
						this.getCdstockService().saveOrStock(stockObject);
					}

				} else {

				}
				/**
				 * 对配送单进行设置
				 */
				
				DistributionOrder dbObject = this.getDistributionOrderService().setDistributionOrder(replaceCodes(moldingOrderPlans[i]));
				if (dbObject != null) {
					DistributionOrderDetail dbDetail = this.getDistributionOrderDetailService().setDistributionOrderDetail(replaceCodes(moldingOrderPlans[i]), moldingCodes[i]);
					if(dbDetail!=null){
						dbDetail.setProToNums(dbDetail.getProToNums()+shareality_num[i]);
						this.getDistributionOrderService().saveOrDistributionOrderDetail(dbDetail);
					}					
					dbObject.setState("0");
					this.getDistributionOrderService().saveOrDistributionOrder(
							dbObject);
				}
				

			}
			// 不管你印刷与否都会在成型查询那里添加这条数据

			/**
			 * 成型单的添加----------------------start
			 */
			MoldingTeam mtObject = this.getMoldingTeamService().getMoldingTeam(
					moldingCodes[i], moldingOrderPlans[i]);

			MoldingTeam mmObject = new MoldingTeam();
			mmObject.setTihuoDate(tihuoDates[i]);
			mmObject.setRunshOrder(rushOrders[i]);
			mmObject.setProductCode(moldingCodes[i]);
			mmObject.setMoldingOrderplan(moldingOrderPlans[i]);
			mmObject.setJiqiNum(moldingTeam.getJiqiNum());
			mmObject.setBanhaoNum(moldingTeam.getBanhaoNum());
			mmObject.setTijiaoDate(moldingTeam.getTijiaoDate());
			mmObject.setProductName(shaproduct_name[i]);
			mmObject.setProductSize(shasize[i]);
			mmObject.setProductColor(shacolor[i]);
			mmObject.setProductPackstyleWay(shaspeed[i]);
			mmObject.setWenduA(shatemperature_A[i]);
			mmObject.setWenduB(shatemperature_B[i]);
			mmObject.setWenduC(shatemperature_C[i]);
			mmObject.setDinghuoNum(shaorder_num[i]);
			mmObject.setYudingNum(shayudingNums[i]);
			mmObject.setYeshengNum(shareality_num[i]);
			mmObject.setShijiNum(shareality_num[i]);
			mmObject.setYaoqiuSx(shayaoqiuSxs[i]);
			mmObject.setChangjia(shaproduct_name[i]);
			mmObject.setXuyongNum(shaxuyongliaoNums[i]);
			mmObject.setHuanNum(Double.parseDouble(shahuan_num[i]));
			mmObject.setFeiliaoNum(Double.parseDouble(shafei_num[i]));
			mmObject.setShijilingNum(shashijiLinNums[i]);
			mmObject.setRemarks(sharemark[i]);
			mmObject.setSelectiveDateA(moldingTeam.getSelectiveDateA());
			mmObject.setSelectiveDateB(moldingTeam.getSelectiveDateB());
			mmObject.setSelectiveDateC(moldingTeam.getSelectiveDateC());
			mmObject.setSelectiveDateD(moldingTeam.getSelectiveDateD());
			mmObject.setSelectiveDateE(moldingTeam.getSelectiveDateE());
			mmObject.setSelectiveDateF(moldingTeam.getSelectiveDateF());
			mmObject.setSelectiveDateAA(moldingTeam.getSelectiveDateAA());
			mmObject.setSelectiveDateAB(moldingTeam.getSelectiveDateAB());
			mmObject.setSelectiveDateAC(moldingTeam.getSelectiveDateAC());
			mmObject.setSelectiveDateAD(moldingTeam.getSelectiveDateAD());
			mmObject.setSelectiveDateAE(moldingTeam.getSelectiveDateAE());
			mmObject.setSelectiveDateAF(moldingTeam.getSelectiveDateAF());
			mmObject.setProductspeedA(moldingTeam.getProductspeedA());
			mmObject.setProductspeedB(moldingTeam.getProductspeedB());
			mmObject.setProductspeedC(moldingTeam.getProductspeedC());
			mmObject.setProductspeedD(moldingTeam.getProductspeedD());
			mmObject.setProductspeedE(moldingTeam.getProductspeedE());
			mmObject.setProductspeedF(moldingTeam.getProductspeedF());
			mmObject.setProductspeedAA(moldingTeam.getProductspeedAA());
			mmObject.setProductspeedAB(moldingTeam.getProductspeedAB());
			mmObject.setProductspeedAC(moldingTeam.getProductspeedAC());
			mmObject.setProductspeedAD(moldingTeam.getProductspeedAD());
			mmObject.setProductspeedAE(moldingTeam.getProductspeedAE());
			mmObject.setProductspeedAF(moldingTeam.getProductspeedAF());
			mmObject.setToleranceCriterionA(moldingTeam
					.getToleranceCriterionA());
			mmObject.setToleranceCriterionB(moldingTeam
					.getToleranceCriterionB());
			mmObject.setToleranceCriterionC(moldingTeam
					.getToleranceCriterionC());
			mmObject.setToleranceCriterionD(moldingTeam
					.getToleranceCriterionD());
			mmObject.setToleranceCriterionE(moldingTeam
					.getToleranceCriterionE());
			mmObject.setToleranceCriterionF(moldingTeam
					.getToleranceCriterionF());
			mmObject.setToleranceCriterionAA(moldingTeam
					.getToleranceCriterionAA());
			mmObject.setToleranceCriterionAB(moldingTeam
					.getToleranceCriterionAB());
			mmObject.setToleranceCriterionAC(moldingTeam
					.getToleranceCriterionAC());
			mmObject.setToleranceCriterionAD(moldingTeam
					.getToleranceCriterionAD());
			mmObject.setToleranceCriterionAE(moldingTeam
					.getToleranceCriterionAE());
			mmObject.setToleranceCriterionAF(moldingTeam
					.getToleranceCriterionAF());
			mmObject.setProDateA(moldingTeam.getProDateA());
			mmObject.setProDateB(moldingTeam.getProDateB());
			mmObject.setProDateC(moldingTeam.getProDateC());
			mmObject.setProDateD(moldingTeam.getProDateD());
			mmObject.setProWorkStateA(moldingTeam.getProWorkStateA());
			mmObject.setProWorkStateB(moldingTeam.getProWorkStateB());
			mmObject.setProWorkStateC(moldingTeam.getProWorkStateC());
			mmObject.setProWorkStateD(moldingTeam.getProWorkStateD());
			mmObject.setProRemarkA(moldingTeam.getProRemarkA());
			mmObject.setProRemarkB(moldingTeam.getProRemarkB());
			mmObject.setProRemarkC(moldingTeam.getProRemarkC());
			mmObject.setProRemarkD(moldingTeam.getProRemarkD());
			mmObject.setProZuG(moldingTeam.getProZuG());
			mmObject.setProJishu(moldingTeam.getProJishu());
			mmObject.setProShenc(moldingTeam.getProShenc());
			this.getMoldingTeamService().save(mmObject);
			if (mtObject == null) {
//				System.out.println("成型单不存在这个东西");
			} else {
				// mtObject.set
//				System.out.println("成型单存在这个东西");
				mtObject.setYeshengNum(mtObject.getYeshengNum()
						+ shayeshengchanNums[i]);
				this.getMoldingTeamService().saveOrMoldingTeam(mtObject);
			}

			/**
			 * 成型单的添加----------------------end
			 */

			// 不管你印刷不印刷都要进行还料

			/**
			 * 进行还料-----------------start
			 */
			//********还料进行处理
			double huannUns = Double.parseDouble(shahuan_num[i]);
			
			if (huannUns > 0) {
				//还料量大于“0”,进行换料
				this.getMaterialTeamService().backTrackMaterialTeam(
						moldingCodes[i], moldingOrderPlans[i], huannUns,
						shashijiLinNums[i]);
			} else {
				//还料量为“0”,不需进行料换
				if (shashijiLinNums[i] > 0) {
					this.getMaterialTeamService().backTrackMaterialTeamHunZero(
							moldingCodes[i], moldingOrderPlans[i], huannUns,
							shashijiLinNums[i]);
				}
			}
            //********废料进行处理
			double  feiliaoUns=Double.parseDouble(shafei_num[i]);
			if(feiliaoUns>0){
				//改废料重新进行生产
				
	    MaterialProduct MpObject = this.getMaterialProductService().getMaterialProductOrPro(moldingOrderPlans[i], moldingCodes[i]);
		int StateCon=MpObject.getpLState();
		if(StateCon==7){
			MaterialProduct MpBackObject = new MaterialProduct();
			MpBackObject.setProductCode(moldingCodes[i]);
			MpBackObject.setProductName(MpObject.getProductName());
			MpBackObject.setProductColor(MpObject.getProductColor());
			MpBackObject.setProductNorm(MpObject.getProductNorm());
			MpBackObject.setDeliveryDate(MpObject.getDeliveryDate());
			MpBackObject.setRushOrder(MpObject.getRushOrder());
			MpBackObject.setRemainderNum(MpObject.getRemainderNum());
			MpBackObject.setNeedNum(feiliaoUns);
			MpBackObject.setBackMakeState(4);
			MpBackObject.setpLState(1);
			MpBackObject.setPlanOrOrderId(moldingOrderPlans[i]);
			MpBackObject.setFirstYN(1);
			MpBackObject.setProductPackstyle(MpObject.getProductPackstyle());
			MpBackObject.setProductNum(MpObject.getProductNum());
			MpBackObject.setAlreadyProduct(0.000);
			MpBackObject.setProductScal(MpObject.getProductScal());
			MpBackObject.setNumConfirmState(1);
			this.getMaterialProductService().save(MpBackObject);
		}else{
			MpObject.setNeedNum(MpObject.getNeedNum()+feiliaoUns);
			this.getMaterialProductService().saveOrMaterialProduct(MpObject);
		}		
				
	
				
				
				
				
				
				
			}
			/**
			 * 进行还料-----------------end
			 */
			/**
			 * 修改前面的数据molding----------------start
			 */
//			System.out.println("moldingCodes[i]=" + moldingCodes[i]);
//			System.out.println("moldingOrderPlans[i]=" + moldingOrderPlans[i]);
			Molding mObject = this.getMoldingService().getMolding(
					moldingOrderPlans[i], moldingCodes[i]);

			if (shayeshengchanNums[i] > 0) {
				if (shareality_num[i] >= (shaorder_num[i] - shayeshengchanNums[i])) {
					mObject.setShowState(7);

				}
				mObject.setMoldingYJNum(mObject.getMoldingYJNum()
						+ shareality_num[i]);
//				mObject.setMoldingYJNum(mObject.getMoldingYJNum()
//						+ shareality_num[i]);
			} else {
				if (shareality_num[i] >= shaorder_num[i]) {
					mObject.setShowState(7);
				}

				mObject.setMoldingYJNum(shareality_num[i]);

			}

			this.getMoldingService().saveOrMolding(mObject);
			/**
			 * 修改前面的数据molding----------------end
			 */
		}

		/**
		 * chengx工资单的计算--------------------------------------start
		 */
     if(insV==0){
    	 for(int x=0;x<lengths;x++){
				wages = wages + Double.parseDouble(shareality_num[x]+"");;
				funds = funds + Double.parseDouble(shafei_num[x]);
			}
		/**
		 * 人员比对-----------------start-------
		 */
		// 每个人本次制定分到的实际数量
		double shiji_merNum = 0.0;
		// 每个人本次制定分到的 废料数量
		double feiliao_merNum = 0.0;
		String personNames = moldingTeam.getProShenc();
		String lengthss[] = personNames.split(",");
		int personlength = lengthss.length;
		DecimalFormat df = new DecimalFormat("##.000");
		if (personlength > 0) {
			// 大于一个人，需要平分
			shiji_merNum = Double.parseDouble(df.format(wages / personlength));
			feiliao_merNum = Double
					.parseDouble(df.format(funds / personlength));
		} else {
			// 一个人独享
			shiji_merNum = wages;
			feiliao_merNum = funds;
		}

		/**
		 * 人员比对------------------end------
		 */
		/**
		 * 工资单计算------------------------------------------------------start
		 * wages funds
		 */
		ProvideRegime pdobjectA = this.getProvideRegimeService()
		.getProvideRegime("成型","实际领料量",
				moldingTeam.getBanhaoNum(),
				moldingTeam.getJiqiNum());
 double shijichanliangNum = (double) pdobjectA.getSetNum();
double jiangliDJ = pdobjectA.getRewardPrice();
double chengfaDJ = pdobjectA.getPunishPrice();
String uuDate=getCurrentDate();
for (int z = 0; z < personlength; z++) {
	MoldingWages  mwObject=new MoldingWages();
	mwObject.setProStyles("实际产量");
	mwObject.setProvideNums(shijichanliangNum+"");
	mwObject.setProNames(lengthss[z]);
	mwObject.setPoundPrice(jiangliDJ);
	mwObject.setRwardPrice(chengfaDJ);
	mwObject.setRegDate(uuDate);
	mwObject.setThNums(shiji_merNum);
	mwObject.setDiscriminationValue(pdobjectA.getDiscriminationValue());
	this.getMoldingWagesService().save(mwObject);
	
}


ProvideRegime pdobjectB = this.getProvideRegimeService()
		.getProvideRegime("成型","废料",
				moldingTeam.getBanhaoNum(),
				moldingTeam.getJiqiNum());
double feiliaoNum = (double) pdobjectB.getSetNum();
double jiangliDJF = pdobjectB.getRewardPrice();
double chengfaDJF = pdobjectB.getPunishPrice();

for (int z = 0; z < personlength; z++) {
	MoldingWages  mwObject=new MoldingWages();
	mwObject.setProStyles("废料");
	mwObject.setProvideNums(feiliaoNum+"");
	mwObject.setProNames(lengthss[z]);
	mwObject.setPoundPrice(jiangliDJF);
	mwObject.setRwardPrice(chengfaDJF);
	mwObject.setRegDate(uuDate);
	mwObject.setThNums(feiliao_merNum);
	mwObject.setDiscriminationValue(pdobjectB.getDiscriminationValue());
	this.getMoldingWagesService().save(mwObject);
	
}
insV++;
     }


		/**
		 * 工资单计算------------------------------------------------------end
		 */

		/**
		 * chengx工资单的计算---------------------------------------end
		 */

	}

	public cd_Product getCd_Product() {
		return cd_Product;
	}

	public void setCd_Product(cd_Product cd_Product) {
		this.cd_Product = cd_Product;
	}

	public cd_ProductService getCd_ProductService() {
		return cd_ProductService;
	}

	public void setCd_ProductService(cd_ProductService cd_ProductService) {
		this.cd_ProductService = cd_ProductService;
	}

	public Printing getPrinting() {
		return printing;
	}

	public void setPrinting(Printing printing) {
		this.printing = printing;
	}

	public PrintingService getPrintingService() {
		return printingService;
	}

	public void setPrintingService(PrintingService printingService) {
		this.printingService = printingService;
	}

	public MoldingTeam getMoldingTeam() {
		return moldingTeam;
	}

	public void setMoldingTeam(MoldingTeam moldingTeam) {
		this.moldingTeam = moldingTeam;
	}

	public MoldingTeamService getMoldingTeamService() {
		return moldingTeamService;
	}

	public void setMoldingTeamService(MoldingTeamService moldingTeamService) {
		this.moldingTeamService = moldingTeamService;
	}

	@Override
	public MoldingTeam getMoldingTeam(String productCode, String orderplan) {

		return this.getDao().getMoldingTeam(productCode, orderplan);
	}

	public MaterialTeamService getMaterialTeamService() {
		return materialTeamService;
	}

	public void setMaterialTeamService(MaterialTeamService materialTeamService) {
		this.materialTeamService = materialTeamService;
	}

	public Molding getMolding() {
		return molding;
	}

	public void setMolding(Molding molding) {
		this.molding = molding;
	}

	public MoldingService getMoldingService() {
		return moldingService;
	}

	public void setMoldingService(MoldingService moldingService) {
		this.moldingService = moldingService;
	}

	@Override
	public void saveOrMoldingTeam(MoldingTeam moldingTeam) {
		this.getDao().saveOrMoldingTeam(moldingTeam);
	}

	public ProvideRegimeService getProvideRegimeService() {
		return provideRegimeService;
	}

	public void setProvideRegimeService(
			ProvideRegimeService provideRegimeService) {
		this.provideRegimeService = provideRegimeService;
	}

	public ProvideRegime getProvideRegime() {
		return provideRegime;
	}

	public void setProvideRegime(ProvideRegime provideRegime) {
		this.provideRegime = provideRegime;
	}

	public HrPerson getHrPerson() {
		return hrPerson;
	}

	public void setHrPerson(HrPerson hrPerson) {
		this.hrPerson = hrPerson;
	}

	public HrPersonService getHrPersonService() {
		return hrPersonService;
	}

	public void setHrPersonService(HrPersonService hrPersonService) {
		this.hrPersonService = hrPersonService;
	}

	public Cdstock getCdstock() {
		return cdstock;
	}

	public void setCdstock(Cdstock cdstock) {
		this.cdstock = cdstock;
	}

	public CdstockService getCdstockService() {
		return cdstockService;
	}

	public void setCdstockService(CdstockService cdstockService) {
		this.cdstockService = cdstockService;
	}

	public DistributionOrder getDistributionOrder() {
		return distributionOrder;
	}

	public void setDistributionOrder(DistributionOrder distributionOrder) {
		this.distributionOrder = distributionOrder;
	}

	public DistributionOrderService getDistributionOrderService() {
		return distributionOrderService;
	}

	public void setDistributionOrderService(
			DistributionOrderService distributionOrderService) {
		this.distributionOrderService = distributionOrderService;
	}

	public MoldingPrint getMoldingPrint() {
		return moldingPrint;
	}

	public void setMoldingPrint(MoldingPrint moldingPrint) {
		this.moldingPrint = moldingPrint;
	}

	public MoldingPrintService getMoldingPrintService() {
		return moldingPrintService;
	}

	public void setMoldingPrintService(MoldingPrintService moldingPrintService) {
		this.moldingPrintService = moldingPrintService;
	}

	@Override
	public void saveAllMoldingTeamPrint(MoldingTeam moldingTeam,
			String[] moldingCodes, Integer[] orderNums,
			String[] moldingOrderPlans, String[] shaproduct_name,
			String[] shasize, String[] shacolor, String[] shaspeed,
			String[] shatemperature_A, Integer[] shaorder_num,
			Integer[] shayudingNums, Integer[] shareality_num,
			String[] shayaoqiuSxs, String[] shacustomer,
			Double[] shaxuyongliaoNums, String[] shafei_num,
			Double[] shashijiLinNums, String[] sharemark,
			String[] shatemperature_B, Integer[] shayeshengchanNums,
			String[] shahuan_num, String[] shatemperature_C, Date[] tihuoDates,
			String[] rushOrders) {

		/**
		 * 打印编号
		 */
		String CodeNumbers = "04070020101202C1";
		SerialNumberss snObject = this.getSerialNumberssService()
				.getSerialNumberss("成型组打印");
		if (snObject == null) {
			SerialNumberss snmm = new SerialNumberss();
			snmm.setStyCategory("成型组打印");
			snmm.setStyNumberCode(CodeNumbers);
			this.getSerialNumberssService().save(snmm);
		} else {
			String codeF = snObject.getStyNumberCode();
			String DF[] = codeF.split("C");
			int lastCode = Integer.parseInt(DF[1]) + 1;
			CodeNumbers = DF[0] + "C" + lastCode;
			snObject.setStyNumberCode(CodeNumbers);
			this.getSerialNumberssService().setNumCode(snObject);
		}

		int lengths = rushOrders.length;

		MoldingPrint mpObject = new MoldingPrint();
		mpObject.setMoldingPrintCode(CodeNumbers);
		mpObject.setJiqiNum(moldingTeam.getJiqiNum());
		mpObject.setBanhaoNum(moldingTeam.getBanhaoNum());
		mpObject.setTijiaoDate(moldingTeam.getTijiaoDate());
		mpObject.setSelectiveDateA(moldingTeam.getSelectiveDateA());
		mpObject.setSelectiveDateB(moldingTeam.getSelectiveDateB());
		mpObject.setSelectiveDateC(moldingTeam.getSelectiveDateC());
		mpObject.setSelectiveDateD(moldingTeam.getSelectiveDateD());
		mpObject.setSelectiveDateE(moldingTeam.getSelectiveDateE());
		mpObject.setSelectiveDateF(moldingTeam.getSelectiveDateF());
		mpObject.setSelectiveDateAA(moldingTeam.getSelectiveDateAA());
		mpObject.setSelectiveDateAB(moldingTeam.getSelectiveDateAB());
		mpObject.setSelectiveDateAC(moldingTeam.getSelectiveDateAC());
		mpObject.setSelectiveDateAD(moldingTeam.getSelectiveDateAD());
		mpObject.setSelectiveDateAE(moldingTeam.getSelectiveDateAE());
		mpObject.setSelectiveDateAF(moldingTeam.getSelectiveDateAF());
		mpObject.setProductspeedA(moldingTeam.getProductspeedA());
		mpObject.setProductspeedB(moldingTeam.getProductspeedB());
		mpObject.setProductspeedC(moldingTeam.getProductspeedC());
		mpObject.setProductspeedD(moldingTeam.getProductspeedD());
		mpObject.setProductspeedE(moldingTeam.getProductspeedE());
		mpObject.setProductspeedF(moldingTeam.getProductspeedF());
		mpObject.setProductspeedAA(moldingTeam.getProductspeedAA());
		mpObject.setProductspeedAB(moldingTeam.getProductspeedAB());
		mpObject.setProductspeedAC(moldingTeam.getProductspeedAC());
		mpObject.setProductspeedAD(moldingTeam.getProductspeedAD());
		mpObject.setProductspeedAE(moldingTeam.getProductspeedAE());
		mpObject.setProductspeedAF(moldingTeam.getProductspeedAF());
		mpObject.setToleranceCriterionA(moldingTeam.getToleranceCriterionA());
		mpObject.setToleranceCriterionB(moldingTeam.getToleranceCriterionB());
		mpObject.setToleranceCriterionC(moldingTeam.getToleranceCriterionC());
		mpObject.setToleranceCriterionD(moldingTeam.getToleranceCriterionD());
		mpObject.setToleranceCriterionE(moldingTeam.getToleranceCriterionE());
		mpObject.setToleranceCriterionF(moldingTeam.getToleranceCriterionF());
		mpObject.setToleranceCriterionAA(moldingTeam.getToleranceCriterionAA());
		mpObject.setToleranceCriterionAB(moldingTeam.getToleranceCriterionAB());
		mpObject.setToleranceCriterionAC(moldingTeam.getToleranceCriterionAC());
		mpObject.setToleranceCriterionAD(moldingTeam.getToleranceCriterionAD());
		mpObject.setToleranceCriterionAE(moldingTeam.getToleranceCriterionAE());
		mpObject.setToleranceCriterionAF(moldingTeam.getToleranceCriterionAF());
		mpObject.setProDateA(moldingTeam.getProDateA());
		mpObject.setProDateB(moldingTeam.getProDateB());
		mpObject.setProDateC(moldingTeam.getProDateC());
		mpObject.setProDateD(moldingTeam.getProDateD());
		mpObject.setProWorkStateA(moldingTeam.getProWorkStateA());
		mpObject.setProWorkStateB(moldingTeam.getProWorkStateB());
		mpObject.setProWorkStateC(moldingTeam.getProWorkStateC());
		mpObject.setProWorkStateD(moldingTeam.getProWorkStateD());
		mpObject.setProRemarkA(moldingTeam.getProRemarkA());
		mpObject.setProRemarkB(moldingTeam.getProRemarkB());
		mpObject.setProRemarkC(moldingTeam.getProRemarkC());
		mpObject.setProRemarkD(moldingTeam.getProRemarkD());
		mpObject.setProZuG(moldingTeam.getProZuG());
		mpObject.setProJishu(moldingTeam.getProJishu());
		mpObject.setProShenc(moldingTeam.getProShenc());
		for (int i = 0; i < lengths; i++) {
			MoldingPrintDetail mpd = new MoldingPrintDetail();
			mpd.setProductName(shaproduct_name[i]);
			mpd.setProductSize(shasize[i]);
			mpd.setProductColor(shacolor[i]);
			mpd.setProductPackstyleWay(shaspeed[i]);
			mpd.setWenduA(shatemperature_A[i]);
			mpd.setWenduB(shatemperature_B[i]);
			mpd.setWenduC(shatemperature_C[i]);
			if (shaorder_num[i] == null) {
				mpd.setDinghuoNum(0);
			} else {
				mpd.setDinghuoNum(shaorder_num[i]);
			}

			if (shayeshengchanNums[i] == null) {
				mpd.setYeshengNum(0);
			} else {
				mpd.setYeshengNum(shayeshengchanNums[i]);
			}

			if (shayudingNums[i] == null) {
				mpd.setYudingNum(0);
			} else {
				mpd.setYudingNum(shayudingNums[i]);
			}
			if (shareality_num[i] == null) {
				mpd.setShijiNum(0);
			} else {
				mpd.setShijiNum(shareality_num[i]);
			}

			mpd.setYaoqiuSx(shayaoqiuSxs[i]);
			mpd.setChangjia(shacustomer[i]);

			if (shaxuyongliaoNums[i] == null || "".equals(shaxuyongliaoNums[i])) {
				mpd.setXuyongNum(0.00);
			} else {
				mpd.setXuyongNum(shaxuyongliaoNums[i]);
			}

			if (shahuan_num[i] == null || "".equals(shahuan_num[i])) {
				mpd.setHuanNum(0.00);
			} else {
				mpd.setHuanNum(Double.parseDouble(shahuan_num[i]));
			}
			if (shafei_num[i] == null || "".equals(shahuan_num[i])) {
				mpd.setFeiliaoNum(0.00);
			} else {
				mpd.setFeiliaoNum(Double.parseDouble(shafei_num[i]));
			}

			if (shashijiLinNums[i] == null || "".equals(shahuan_num[i])) {
				mpd.setShijilingNum(0.00);
			} else {
				mpd.setShijilingNum(shashijiLinNums[i]);
			}
			mpd.setRemarks(sharemark[i]);
			mpObject.addDetail(mpd);
		}
		this.getMoldingPrintService().save(mpObject);
	}

	public SerialNumberssService getSerialNumberssService() {
		return serialNumberssService;
	}

	public void setSerialNumberssService(
			SerialNumberssService serialNumberssService) {
		this.serialNumberssService = serialNumberssService;
	}

	public StockPrecautionaryService getStockPrecautionaryService() {
		return stockPrecautionaryService;
	}

	public void setStockPrecautionaryService(
			StockPrecautionaryService stockPrecautionaryService) {
		this.stockPrecautionaryService = stockPrecautionaryService;
	}

	@Override
	public List<MoldingTeam> getMoldingTeamOrderpLan(String orderplan) {
		// TODO Auto-generated method stub
		return this.getDao().getMoldingTeamOrderpLan(orderplan);
	}

	public static String getCurrentDate() {
		Calendar cal = Calendar.getInstance();
		int year = cal.get(Calendar.YEAR);
		int month = cal.get(Calendar.MONTH) + 1;
		int days=cal.get(Calendar.DATE);   
	    return days+"/"+month + "/" + year;
	}

	public EarningSalService getEarningSalService() {
		return earningSalService;
	}

	public void setEarningSalService(EarningSalService earningSalService) {
		this.earningSalService = earningSalService;
	}

	public DistributionOrderDetailService getDistributionOrderDetailService() {
		return distributionOrderDetailService;
	}

	public void setDistributionOrderDetailService(
			DistributionOrderDetailService distributionOrderDetailService) {
		this.distributionOrderDetailService = distributionOrderDetailService;
	}

	public MaterialWagesService getMaterialWagesService() {
		return materialWagesService;
	}

	public void setMaterialWagesService(
			MaterialWagesService materialWagesService) {
		this.materialWagesService = materialWagesService;
	}

	public MoldingWagesService getMoldingWagesService() {
		return moldingWagesService;
	}

	public void setMoldingWagesService(MoldingWagesService moldingWagesService) {
		this.moldingWagesService = moldingWagesService;
	}

	public PrintWagesService getPrintWagesService() {
		return printWagesService;
	}

	public void setPrintWagesService(PrintWagesService printWagesService) {
		this.printWagesService = printWagesService;
	}

	String replaceCodes(String codes) {
		String rr[] = codes.split("LH");
		String xx = "";
		if (rr.length == 1) {
			xx = codes;
		} else {
			xx = rr[1];
		}
		return xx;
	}

	public MaterialProductService getMaterialProductService() {
		return materialProductService;
	}

	public void setMaterialProductService(
			MaterialProductService materialProductService) {
		this.materialProductService = materialProductService;
	}

	public CrmCustomerService getCrmCustomerService() {
		return crmCustomerService;
	}

	public void setCrmCustomerService(CrmCustomerService crmCustomerService) {
		this.crmCustomerService = crmCustomerService;
	}

	public SaleOrderService getSaleOrderService() {
		return saleOrderService;
	}

	public void setSaleOrderService(SaleOrderService saleOrderService) {
		this.saleOrderService = saleOrderService;
	}

}
